/**
* <p>Title: PageElementHandler.java</p>
* <p>Description: 页面元素驱动</p>
* <p>Company: www.huoyunren.com</p>
* @author duanxiangyun
* @date 2015年1月7日
* @version 1.0
*/
package com.hxbd.test.handles;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * 此文件用于获取各个功能页面对应的Properties配置文件信息
 */
public class PageElementHandler extends Properties
{
    private static final long serialVersionUID = 1L;

	//  business pc property files
    private static final String       STORE_SETTING       			        = "StoreSetting.properties";
    private static Logger             LOG                    			    = Logger.getLogger(PageElementHandler.class);

	/**
	 * 构造方法，并读取配置文件
	 * @param prop 配置文件名
	 */
    public PageElementHandler(String prop)
    {
        if (LOG.isDebugEnabled())
        {
            LOG.debug("Properties name = " + prop);
        }
        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(prop);
        BufferedReader bf = null;
        if (in == null)
        {
            LOG.error("Can't find the corresponding property file: [" + prop + "]");
            return;
        }
        try
        {
        	bf = new BufferedReader(new InputStreamReader(in));
    		this.load(bf);
        }
        catch (IOException e)
        {
            e.printStackTrace();
            LOG.error(e.toString());
        }
        finally
        {
            try
            {
                in.close();
                bf.close();
            }
            catch (IOException e)
            {
                e.printStackTrace();
                LOG.error(e.toString());
            }
        }
    }
    /**
     * 获得properties文件中属性
     * @param profile
     * @return PageElementHandler
     */
    public static PageElementHandler getProperties(String profile)
    {
        return (new PageElementHandler(profile ));
    }
    /**
     * 配置文件读取：公共设置存储
     * @return PageElementHandler
     */
    public static PageElementHandler getStoreSettingProperties()
    {
        return (new PageElementHandler(STORE_SETTING ));
    }
    /**
     * 配置文件读取：公共设置存储
     * @param name
     * @return
     */
    public static String getStoreSettingPropertie(String name)
    {
        return (new PageElementHandler(STORE_SETTING )).getProperty(name);
    }
}